///////////////////////////////////////////////////////////////////////////////
//
// lighthouse3D - 3D Software Library
//
// File: CFileHandler.h
//
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2003-2013 Marcus Reinhardt
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
///////////////////////////////////////////////////////////////////////////////
//
// You can find a copy of the GNU General Public License (gpl.txt) in the
// directory of the library.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef _CFileHandler_H_
#define _CFileHandler_H_

#include "C3DSFileHandler.h"
#include "CBMPFileHandler.h"
#include "COBJFileHandler.h"
#include "CTGAFileHandler.h"
#include "CMeshStorage.h"
#include "CBasicClasses.h"

#define _noFileError_              0
#define _errorOnLoading3DSFile_    1
#define _errorOnLoading3DSTexture_ 2
#define _errorOnLoadingBMPFile_    3
#define _errorOnLoadingTGAFile_    4
#define _errorOnLoadingOBJFile_    5
#define _errorOnSavingBMPFile_     13
#define _errorOnSavingTGAFile_     14

//! Every function loading or saving data

class CFileHandler {

  public:

    ///////////////////////////////////////////////////////////////////////////////
    // constructor/destructor
    ///////////////////////////////////////////////////////////////////////////////
    CFileHandler();
    ~CFileHandler();

    ///////////////////////////////////////////////////////////////////////////////
    // load functions
    ///////////////////////////////////////////////////////////////////////////////
    bool load3DSToMeshStorage(const char *fname, CMeshStorage *storageHandler);
    bool loadOBJToMeshStorage(const char *fname, CMeshStorage *storageHandler);

    bool loadImageToTexture(const char *fname, TMeshTexture *texHandler);
    bool loadBMPToTexture(const char *fname, TMeshTexture *texHandler);
    bool loadTGAToTexture(const char *fname, TMeshTexture *texHandler);

    bool loadImageToPicture(const char *fname, TPictureData *picHandler);
    bool loadBMPToPicture(const char *fname, TPictureData *picHandler);
    bool loadTGAToPicture(const char *fname, TPictureData *picHandler);

    ///////////////////////////////////////////////////////////////////////////////
    // save functions
    ///////////////////////////////////////////////////////////////////////////////
    bool saveImageFromPicture(const char *fname, TPictureData *picHandler);
    bool saveBMPFromPicture(const char *fname, TPictureData *picHandler);
    bool saveTGAFromPicture(const char *fname, TPictureData *picHandler);

    ///////////////////////////////////////////////////////////////////////////////
    // error functions
    ///////////////////////////////////////////////////////////////////////////////
    int		 getErrorLevel() { return fileError; }
    void	 setErrorLevel(int e) { fileError = e; }
    unsigned int get3DSFailureColor() { return color3DSFailure; }
    void	 set3DSFailureColor(unsigned int c) {color3DSFailure = c; }
    unsigned int getOBJFailureColor() { return colorOBJFailure; }
    void	 setOBJFailureColor(unsigned int c) {colorOBJFailure = c; }

    ///////////////////////////////////////////////////////////////////////////////
    // other functions
    ///////////////////////////////////////////////////////////////////////////////
    void getExtensionFromFilename(char *szFileName, char *szExtension);
    void getPathFromFilename(char *szFileName, char *szPath);
    void release();

  private:

      int fileError;
	  unsigned int color3DSFailure;
	  unsigned int colorOBJFailure;

      C3DSFileHandler fileHandler3DS;
      CBMPFileHandler fileHandlerBMP;
      COBJFileHandler fileHandlerOBJ;
      CTGAFileHandler fileHandlerTGA;

      TMeshTexture    tex;
	  TPictureData	  picTemp;

};

#endif
